/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */

import { DepartmentsVo } from "@/modules/departments/api/departments";
import type { MaFormItem } from "@mineadmin/form";
import type { WordGroupVo } from "~/word/api/group.ts";

import { page } from "~/word/api/group";
//@ts-ignore
import RemoteSelect from "@/components/ma-remote-select/index.vue";
//@ts-ignore
import PhoneticAlphabet from "../components/phoneticAlphabet.vue";
//@ts-ignore
import UploadFile from "@/components/ma-upload-file/index.vue";
export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: WordGroupVo
): MaFormItem[] {
  if (formType === "add") {
    // model.password = "123456";
  }

  return [
    {
      label: () => t("word-manage.group"),
      prop: "group_id",
      render: () => RemoteSelect,
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: t("word-manage.group") }),
        api: () => new Promise((resolve) => resolve(page({ page_size: 999 }))),
        dataHandle: (response: any) => {
          return response.data.list?.map((item: WordGroupVo) => {
            return { label: `${item.name}`, value: item.id };
          });
        },
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", { msg: t("word-manage.group") }),
          },
        ],
      },
    },
    {
      label: () => t("word-manage.word"),
      prop: "word",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: t("word-manage.word") }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", { msg: t("word-manage.word") }),
          },
        ],
      },
    },
    {
      label: () => t("word-manage.interpretation"),
      prop: "interpretation",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: t("word-manage.interpretation"),
        }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", {
              msg: t("word-manage.interpretation"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("word-manage.origin_word"),
      prop: "origin_word",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: t("word-manage.origin_word"),
        }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", {
              msg: t("word-manage.origin_word"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("word-manage.audio"),
      prop: "audio",
      render: () => UploadFile,
      renderProps: {
        fileType: ["mp3"],
        title: "上传音频",
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredSelect", {
              msg: t("word-manage.audio"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("word-manage.phonetic_alphabet"),
      prop: "phonetic_alphabet",
      render: () => PhoneticAlphabet,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: t("word-manage.phonetic_alphabet"),
        }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", {
              msg: t("word-manage.phonetic_alphabet"),
            }),
          },
        ],
      },
    },
  ];
}
